<?php
// +----------------------------------------------------------------------
// | Iecms [ Make the most exquisite CMS ]
// +----------------------------------------------------------------------
// | Copyright (c) 2009~2019 http://www.iemoo.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: iemoo <i@iemoo.com>
// +----------------------------------------------------------------------
// | DateTime: 2019/11/19 11:08
// +----------------------------------------------------------------------
namespace app\admin\controller;

use app\common\model\Member;
use app\common\model\Message;


use think\facade\Db;
use think\facade\Config;
use think\facade\App;
use think\facade\Cache;
use think\facade\View;


class Index extends Base
{

    public function index()
    {
         //系统信息
        $version = Db::query('SELECT VERSION() AS ver');
        $config = [
            'url' => $_SERVER['HTTP_HOST'],
            'document_root' => $_SERVER['DOCUMENT_ROOT'],
            'server_os' => PHP_OS,
            'server_port' => $_SERVER['SERVER_PORT'],
            'server_ip' => isset($_SERVER['SERVER_ADDR']) ? $_SERVER['SERVER_ADDR'] : '',
            'server_soft' => $_SERVER['SERVER_SOFTWARE'],
            'php_version' => PHP_VERSION,
            'mysql_version' => $version[0]['ver'],
            'max_upload_size' => ini_get('upload_max_filesize'),
            'version' => App::version(),
            'iecms_version' => Config::get('app.iecms_version'),
        ];


		//查找昨天注册用户数量
        $member = Member::whereDay('create_time', 'yesterday')->count();

        //查找待处理留言信息
        $message = Message::where('status', '0')->count();

		View::assign('config',$config);
		View::assign('message',$message);
		View::assign('member',$member);
		return View::fetch('index');
    }


	// 清除缓存
    public function recycle()
    {
		Cache::clear();

		$path = App::getRootPath() . 'runtime' . DIRECTORY_SEPARATOR;
        if ($this->_deleteDir($path)) {			
            $result['msg'] = '清除缓存成功!';
            $result['code'] = 1;
        } else {
            $result['msg'] = '清除缓存失败!';
            $result['code'] = 0;
        }
        return json($result);
    }

    // 执行删除
    private function _deleteDir($R)
    {
        $handle = opendir($R);
        while (($item = readdir($handle)) !== false) {
            if ($item != '.' and $item != '..') {
                if (is_dir($R . DIRECTORY_SEPARATOR . $item)) {
                    $this->_deleteDir($R . DIRECTORY_SEPARATOR . $item);
                } else {
                    if ($item != '.gitignore' && $item != 'services.php') {
                        if (!unlink($R . DIRECTORY_SEPARATOR . $item)) {
                            return false;
                        }
                    }
                }
            }
        }
        closedir($handle);
        return true;
       // return @rmdir($R); //删除空的目录
    }
}
